<template>
    <div>
        <div class='crumbs'>
            <el-breadcrumb separator='/'>
                <el-breadcrumb-item>
                    <i class='el-icon-lx-cascades'></i> 题库
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class='container'>
            <div class='handle-box'>
<!--                题目难度-->
<!--                <el-select clearable v-model='query.difficulty' placeholder='500~1000' class='handle-select mr10'>-->
<!--                    <el-option key='1' label='500~1000' value='1000'></el-option>-->
<!--                    <el-option key='2' label='1000~1500' value='1500'></el-option>-->
<!--                    <el-option key='3' label='1500~2000' value='2000'></el-option>-->
<!--                    <el-option key='4' label='2000~2500' value='2500'></el-option>-->
<!--                </el-select>-->
<!--                题目类型-->
<!--                <el-select clearable filterable v-model='query.tag' placeholder='图论' class='handle-select mr10'>-->
<!--                    <el-option key='1' label='图论' value='1'></el-option>-->
<!--                    <el-option key='2' label='搜索' value='2'></el-option>-->
<!--                    <el-option key='3' label='数论' value='3'></el-option>-->
<!--                    <el-option key='4' label='字符串' value='4'></el-option>-->
<!--                    <el-option key='5' label='网络流' value='5'></el-option>-->
<!--                </el-select>-->
<!--                题目来源-->
<!--                <el-select clearable filterable v-model='query.tag' placeholder='ZJUTOJ' class='handle-select mr10'>-->
<!--                    <el-option key='1' label='CodeForces' value='1'></el-option>-->
<!--                    <el-option key='2' label='洛谷' value='2'></el-option>-->
<!--                    <el-option key='3' label='PTA' value='3'></el-option>-->
<!--                    <el-option key='4' label='51Nod' value='4'></el-option>-->
<!--                    <el-option key='5' label='ZJUTOJ' value='5'></el-option>-->
<!--                </el-select>-->
<!--                <el-input v-model='query.probID' placeholder='题目ID' class='handle-input mr10'></el-input>-->
<!--                <el-button type='primary' icon='el-icon-search' @click='handleSearch' class = 'btn' style=''></el-button>-->
            </div>
            <el-table
                :data='tableData'
                border
                class='table'
                ref='multipleTable'
                header-cell-class-name='table-header'
                @selection-change='handleSelectionChange'
            >
                <el-table-column type='selection' width='55' align='center'></el-table-column>
                <el-table-column prop='probID' label='题号'></el-table-column>
                <el-table-column label='题目名称'>
                    <template #default='scope'>
                        <router-link :to="{path:'/problem',
                        query:{
                            id:scope.row.probID,
                            name: scope.row.probName,
                            author: scope.row.probAuthor,
                            school: scope.row.probSchool,
                            time: scope.row.timeLimit,
                            memory: scope.row.memoryLimit
                        }}">
                            {{ scope.row.probName }}
                        </router-link>
                    </template>
                </el-table-column>
<!--                <el-table-column prop='tag' label='标签'></el-table-column>-->
                <el-table-column label='状态' align='center'>
<!--                    <template #default='scope'>-->
<!--                        <el-tag class='tag'-->
<!--                                v-if="scope.row.status !== ''"-->
<!--                                :type="scope.row.status[0] === 'A' ? 'success' : 'danger'"-->
<!--                        >{{ scope.row.status }}-->
<!--                        </el-tag>-->
<!--                    </template>-->
                </el-table-column>
                <el-table-column prop='timeLimit' label='时间限制(ms)'></el-table-column>
                <el-table-column prop='memoryLimit' label='内存限制(KB)'></el-table-column>
                <el-table-column prop='difficulty' label='难度'></el-table-column>
                <el-table-column prop='solvedNum' label='通过人数'></el-table-column>
            </el-table>
            <div class='pagination'>
                <el-pagination
                    background
                    layout='total, prev, pager, next'
                    :current-page='query.pageIndex'
                    :page-size='query.pageSize'
                    :total='pageTotal'
                    @current-change='handlePageChange'
                ></el-pagination>
            </div>
        </div>

    </div>
</template>

<script>
import { fetchProblem } from '../../api/index';

export default {
    name: 'problemset',
    data() {
        return {
            query: {
                pageIndex: 1,
                pageSize: 10
            },
            tableData: [],
            multipleSelection: [],
            delList: [],
            // editVisible: false,
            pageTotal: 0,
            form: {},
            idx: -1,
            id: -1,
            hideSolve: 0
        };
    },
    mounted:function(){
        this.load_probs()
    },
    // created() {
    //     this.getData();
    // },
    methods: {
        // // 获取 easy-mock 的模拟数据
        // getData() {
        //     fetchProblem(this.query).then(res => {
        //         console.log(res);
        //         this.tableData = res.list;
        //         this.pageTotal = res.pageTotal || 50;
        //     });
        // },
        load_probs() {
            var _this = this
            this.$axios.get('/problems').then(resp => {
                if(resp && resp.status === 200) {
                    _this.tableData = resp.data
                }
            })
        },
        // 触发搜索按钮
        handleSearch() {
            this.$set(this.query, 'pageIndex', 1);
            this.getData();
        },
        // 分页导航
        handlePageChange(val) {
            this.$set(this.query, 'pageIndex', val);
            this.getData();
        }    ,
        // 多选操作
        handleSelectionChange(val) {
            this.multipleSelection = val;
        }
    }
};
</script>

<style scoped>
.handle-box {
    margin-top: 20px;
    margin-bottom: 50px;
    text-align: center;
}

.table {
    width: 100%;
    font-size: 1.2em;
}

.tag {
    font-size: 1.0em;
}

a {
    color: #20a0ff;
}

.handle-select {
    width: 120px;
}

.handle-input {
    width: 300px;
    display: inline-block;
}

.mr10 {
    margin-right: 10px;
}

</style>
